/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import DAO.DAO_FeedBack;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author THANHDAT
 */
@ManagedBean
@RequestScoped
public class FeedbackBean {

    String title;
    String name;
    String date;
    String content;

    /** Creates a new instance of FeedbackBean */
    public FeedbackBean() {
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void clearUser(){
        this.title = "";
        this.name = "";
        this.date = "";
        this.content = "";
    }
    
    public void addnewFeedBack() {
        try {
//            Calendar now = Calendar.getInstance();
            Calendar cal = new GregorianCalendar();

            int month = cal.get(Calendar.MONTH);
            int year = cal.get(Calendar.YEAR);
            int day = cal.get(Calendar.DAY_OF_MONTH);
            String insertday = day + "/" + (month + 1) + "/" + year;
            DAO_FeedBack.insertFeedback(title, name, insertday, content);
            addMessage("Your feedback has been accepted!");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void addMessage(String summary) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}
